package bstsetcode;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/13 10:54
 * 实现Comparable接口需要重写compareTo方法
 */
public class Student implements Comparable<Student>{


    private String name;
    private int score;

    public Student(String name, int score) {
        this.name = name;
        this.score = score;
    }



    @Override
    public boolean equals(Object student) {
        if (this == student) return true;
        if(student == null) return false;
        if (!(student instanceof Student)) return false;
        Student another = (Student) student;
        return this.name.equals(another.name);
    }

    /**
     * 当前的类和另一类比较
     * @param another  传来的another
     * @return 当前的类比传来的another要小，返回一个负数
     */
    @Override
    public int compareTo(Student another) {
        return this.score - another.score;
    }

    @Override
    public String toString() {
        return "Student{" +
                "name='" + name + '\'' +
                ", score=" + score +
                '}';
    }
}
